package com.egao.common.module.outer.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.outer.entity.OuterMutual;
import com.egao.common.module.outer.service.OuterMutualService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 校外双选会控制层
 * @author pyx
 */
@Api(tags = "校外双选会管理")
@RestController
@RequestMapping("${api}")
public class OuterMutualController extends BaseController {
    @Autowired
    private OuterMutualService outerMutualService;

    @PreAuthorize("hasAuthority('outer:mutual:list')")
    @ApiOperation("分页校外双选会")
    @OperLog(value = "校外双选会管理", desc = "分页查询校外双选会信息")
    @GetMapping("/outer/mutual/page")
    public PageResult<OuterMutual> page(HttpServletRequest request) {
        PageParam<OuterMutual> pageParam = new PageParam<>(request);
        pageParam.setDefaultOrder(null, new String[]{"create_time"});
        return new PageResult<>(outerMutualService.listPage(pageParam),pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('outer:mutual:insert')")
    @ApiOperation("添加校外双选会")
    @OperLog(value = "校外双选会管理", desc = "添加校外双选会", result = true)
    @PostMapping("/outer/mutual/insert")
    public JsonResult insert(@RequestBody OuterMutual outerMutual) {
        return outerMutualService.insertOuterMutual(outerMutual);
    }

    @PreAuthorize("hasAuthority('outer:mutual:update')")
    @ApiOperation("修改校外双选会")
    @OperLog(value = "校外双选会管理", desc = "修改校外双选会", result = true)
    @PutMapping("/outer/mutual/update")
    public JsonResult update(@RequestBody OuterMutual outerMutual) {
        return outerMutualService.updateOuterMutual(outerMutual);
    }

    @PreAuthorize("hasAuthority('outer:mutual:delete')")
    @ApiOperation("删除校外双选会")
    @OperLog(value = "校外双选会管理", desc = "删除校外双选会", result = true)
    @DeleteMapping("/outer/mutual/delete")
    public JsonResult delete(Integer id) {
        return outerMutualService.deleteOuterMutual(id);
    }


    @PreAuthorize("hasAuthority('outer:mutual:detail')")
    @ApiOperation("查询单个校外双选会信息")
    @OperLog(value = "校外双选会管理", desc = "查询单个校外双选会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "校外双选会id", required = false, dataType = "Integer", paramType = "query"),
    })
    @GetMapping("/outer/mutual/get")
    public JsonResult listGetId(Integer id) {
        return outerMutualService.getId(id);
    }
}
